'use strict';
/**
 * rest controller
 * @type {Class}
 */
import Base from '../../common/controller/base.js';
export default class extends Base{
  /**
   * init
   * @param  {Object} http []
   * @return {}      []
   */
  init(http){
    super.init(http);
    let userSerive = think.service('user', 'user');
    this.userSerive= new userSerive();
  }
  /**
   * before magic method
   * @return {Promise} []
   */

  async registerAction(){
    let self=this;
    let allParams = self.post();
    let secret=this.config('secret');
    let user=await self.userSerive.addUser(allParams,secret)
    if(typeof user!=='number'){
      return self.success(user);
    }else{
      return self.fail(user);
    }
  }

  async loginAction(){
    let self=this;
    let allParams = self.post();
    let secret=this.config('secret');
    let user=await self.userSerive.getUser(allParams,secret)
    if(typeof user!=='number'){
      return self.success(user);
    }else{
      return self.fail(user);
    }
  }

  async smsAction(){
    let self=this;
    let allParams = self.post();
    let sms=await self.userSerive.sms(allParams)
    if(typeof sms!=='number'){
      return self.success(sms);
    }else{
      return self.fail(sms);
    }
  }

  async addAction(){
    let self=this;
    let allParams = self.post();
    let user=await self.userSerive.addAdminUser(allParams)
    if(typeof user==='number'){
      return self.fail(user);
    }else{
      return self.success(user);
    }
  }

  async getAction(){

  }
}
